/*!
\copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.\n
            All Rights Reserved.\n
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\defgroup   dfu_version_share_profile DFU Version Share Profile
\ingroup    dfu
\brief      Public interface for DFU Version Sharing Profile.

            This module manages the DFU Version Profile for
            sharing of dfu version data between earbuds.
*/

/*! \addtogroup dfu_version_share_profile
 @{
*/

#ifndef DFU_VERSION_SHARE_PROFILE_PRIVATE_H_
#define DFU_VERSION_SHARE_PROFILE_PRIVATE_H_

#include "domain_message.h"
#include <message_.h>
#include <bdaddr_.h>
#include <vm.h>

#include <rtime.h>
#include <message.h>

#include <logging.h>
#include <panic.h>
#include <system_clock.h>
#include <stream.h>
#include <sink.h>
#include <source.h>
#include <stdlib.h>
#include <bt_device.h>

typedef struct
{
    uint16 major;
    uint16 minor;
    uint16 config;
} dfu_version_share_profile_dfu_version_t;

/*! \brief Events sent by DFU Version Share Profile to client. */
typedef enum
{

    /* Indication to disconnect the L2CAP channel b/w earbuds.
    Sent to only Central earbud. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_DISCONNECT = INTERNAL_MESSAGE_BASE,

    /*! Confirmation of DFU Version Share Profile disconnection.
    Sent to both Central and Peripheral earbuds. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_DISCONNECTED,

    /*! Indication to connect the L2CAP channel b/w earbuds.
    Sent to only Central earbud. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_CONNECT,

    /*! Confirmation of DFU Version Share Profile connection.
    Sent to both Central and Peripheral earbuds. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_CONNECTED,

    /*! Indication that version data has been received.
    It can be received in both Central and Peripheral earbud. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_DATA_RECEIVED,

    /*! Indication that version data can be sent via the the DFU Version Share Profile link.
    It can be received in both Central and Peripheral earbuds. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_READY_TO_SEND,

    /* Indication to transfer the data to the peer earbud*/
    DFU_VERSION_SHARE_PROFILE_INTERNAL_SEND_DATA,

    /* Indication to process the data received from the peer earbud*/
    DFU_VERSION_SHARE_PROFILE_INTERNAL_PROCESS_RECEIVED_DATA,

    /*! Indication to check Version Mismatch between two earbuds.
    Sent to both Central and Peripheral earbuds. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_COMPARE_DFU_VERSION,

    /*! Indication that some timeout has occured. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_TIMEOUT,

    /*! Indication that ACL timeout has occured. */
    DFU_VERSION_SHARE_PROFILE_INTERNAL_TIMEOUT_ACL,

} dfu_version_share_msg_private_t;


/*! \brief Confirmation message with the result of the registration with DFU Version Share Profile request
           initiated when DfuVersionShareProfile_Register(Task) is invoked in each earbud.*/
typedef struct
{
    /*! Status of the registration request. */
    bool status;
} DFU_VERSION_SHARE_PROFILE_CLIENT_REGISTERED_T;

/*! \brief Status codes used by DFU Version Share Profile. */
typedef enum
{
    /*! DFU Version Share Profile connected to peer. */
    dfu_version_share_profile_status_peer_connected = 0,

    /*! Unable to connect DFU Version Share Profile with peer. */
    dfu_version_share_profile_status_peer_connect_failed,

    /*! DFU Version Share Profile disconnected. */
    dfu_version_share_profile_status_peer_disconnected
} version_profile_status_t;

/*! \brief Confirmation message with the result of a DFU Version Share Profile connection request initiated
           when #DfuVersionShareProfile_Connect(Task, const bdaddr*) is invoked in the Central earbud.*/
typedef struct
{
    /*! Status of the connection request. */
    version_profile_status_t status;

    /*! Sink for the stream associated to this connection. */
    Sink sink;
} DFU_VERSION_SHARE_PROFILE_CONNECTED_T;

/*! \brief Disconnect reasons. */
typedef enum
{
    /*! The disconnection request was successful.*/
    sp_disconnect_successful,

    /*! Unsolicited disconnection due to L2CAP layer link loss. */
    sp_disconnect_l2cap_link_loss,

    /*! The disconnection request failed.*/
    sp_disconnect_error
} sp_disconnect_status_with_reason_t;

/*! \brief Message used to convey the result of a disconnection request
           initiated when DfuVersionShareProfile_Disconnect(Task) in invoked,
           or as a result of an unsolicited disconnection indication. */
typedef struct
{
    /*! Reason of the disconnection. */
    sp_disconnect_status_with_reason_t reason;

    /*! Status of the disconnection. */
    version_profile_status_t status;
} DFU_VERSION_SHARE_PROFILE_DISCONNECTED_T;

/*! \brief Message indicating that version data has been received from the peer earbud. */
typedef struct
{
    /*! Source for the stream associated to this profile's connection.
        DFU Version Share Profile does not remove any data from this source.
        The client must read the version data from this source when
        receiving this message. */
    Source source;
} DFU_VERSION_SHARE_PROFILE_DATA_RECEIVED_T;

/*! \brief Message indicating that version data can be sent to the peer earbud. */
typedef struct
{
    /*! Sink for the stream associated to this connection. */
    Sink sink;
} DFU_VERSION_SHARE_PROFILE_READY_TO_SEND_T;


#endif /* DFU_VERSION_SHARE_PROFILE_PRIVATE_H_ */

/*! @} End group documentation in Doxygen */

